package cn.e_eap.esite.web.filter;

import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletResponse;

public class JSPFilter implements Filter {

	private boolean enabled;

	@Override
	public void destroy() {

	}

	@Override
	public void doFilter(ServletRequest sreq, ServletResponse sres,
			FilterChain chain) throws IOException, ServletException {
		if (!enabled) {
			chain.doFilter(sreq, sres);
			return;
		}
		HttpServletResponse response = (HttpServletResponse) sres;
		response.sendError(404);
	}

	@Override
	public void init(FilterConfig config) throws ServletException {
		enabled = "true".equalsIgnoreCase(config.getInitParameter("enabled"));

	}

}
